﻿@using GridMvc.Html
@model BeYourMarket.Web.Models.SearchListingModel

@{
    Layout = null;
}

@helper GetCategoryName(int id)
{
    @Model.Categories.Single(x => x.ID == id).Name
}

@helper GetImage(string url, int ListingID)
{
    <a href="@Url.Action("Listing", "Listing", new { id = ListingID })">
        <img src="@url">
    </a>
}

@helper GetItemLink(string title, int ListingID)
{
    <a href="@Url.Action("Listing", "Listing", new { id = ListingID })">
        @title
    </a>
}

<div class="col-md-12 col-sm-12 col-xs-12">
                        @Html.Grid(Model.Grid).SetLanguage(Context.GetPrincipalAppLanguageForRequest().ToString()).EmptyText("[[[There are no items to display.]]]").Columns(columns =>
                       {
                           columns.Add(x => x.UrlPicture).Encoded(false).Sanitized(false)
                               .SetWidth(150)
                               .RenderValueAs(x => GetImage(x.UrlPicture, x.ListingCurrent.ID)).Titled("[[[Picture]]]");

                           if (Model.CategoryID == 0)
                               columns.Add(x => x.ListingCurrent.CategoryID).RenderValueAs(x => GetCategoryName(x.ListingCurrent.CategoryID)).Titled("[[[Category]]]");

                           columns.Add(x => x.ListingCurrent.Title).Encoded(false).Sanitized(false)
                               .RenderValueAs(x => GetItemLink(x.ListingCurrent.Title, x.ListingCurrent.ID)).Titled("[[[Title]]]");

                           columns.Add(x => x.ListingCurrent.Description).Titled("[[[Description]]]").RenderValueAs(x => x.ListingCurrent.Description.PrefixString());
                           columns.Add(x => x.ListingCurrent.PriceFormatted).Titled("[[[Price]]]").Format("{0:N2}");

                           columns.Add(x => x.ListingCurrent.Location).Titled("[[[Location]]]");
                           columns.Add(x => x.ListingCurrent.Created).RenderValueAs(x => x.ListingCurrent.Created.ToShortDateString()).Titled("[[[Created]]]");
                       }).Sortable().Filterable().Selectable(false)
</div>

@section Styles {
    <link href="~/Content/Gridmvc.css" rel="stylesheet" />
    <link href="~/Content/gridmvc.datepicker.min.css" rel="stylesheet" />
}

@section Scripts {
    <script src="~/Scripts/gridmvc.min.js"></script>
    @Html.Partial("_LocalizationGridMvc")
}

